package homework.day03;

import java.io.*;

/**
 * 将当前目录下的所有注册的User对象对应的obj文件获取到，并进行
 * 反序列化后输出每个用户的信息(直接输出反序列化后的User对象即可)
 * @author Xiloer
 *
 */
public class Test02 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //找出User对象文件，以.obj结尾
        File dir = new File(".");
        if (dir.isDirectory()){
            FileFilter filter = (File pathname) -> {//lambda表达式
                    String name = pathname.getName();
                    return name.endsWith(".obj");
            };
            File[] subs = dir.listFiles(filter);
            for (File sub : subs){
                //将查找到的.obj文件反序列化输出
                FileInputStream fis = new FileInputStream(sub.getName());
                ObjectInputStream ois = new ObjectInputStream(fis);

                Object obj = ois.readObject();
                User user = (User)obj;
                System.out.println(user.toString());
                ois.close();
            }
        }

    }

}
